package com.power.service;

import com.alibaba.excel.EasyExcel;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.power.listener.TClueUploadExcelDataListener;
import com.power.mapper.TClueMapper;
import com.power.model.TClue;
import com.power.query.BaseQuery;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.util.List;

@Service
public class ClueServiceImpl implements ClueService {
    @Resource
    private TClueMapper tClueMapper;

    @Override
    public PageInfo<TClue> selectClueListByPage(Integer currentPage, Integer pageSize) {
        PageHelper.startPage(currentPage, pageSize);
        List<TClue> tClues = tClueMapper.selectClueListByPage(BaseQuery.builder().build());
        PageInfo<TClue> pageInfo = new PageInfo<>(tClues);
        return pageInfo;
    }

    @Override
    public void uploadExcelClue(InputStream inputStream, String token) {
        EasyExcel.read(inputStream, TClue.class, new TClueUploadExcelDataListener(tClueMapper, token)).sheet().doRead();
    }

    @Override
    public TClue selectClueDetailById(Integer id) {
        return tClueMapper.selectClueDetailById(id);
    }
}
